package com.example.JavaWebApi.controller.systemController;

import com.example.JavaWebApi.core.apiinterceptors.annotation.Authorize;
import com.example.JavaWebApi.model.entity.systemEntity.ApiRole;
import com.example.JavaWebApi.model.vo.systemVo.ApiRoleVo;
import com.example.JavaWebApi.model.vo.systemVo.ControllerDescription;
import com.example.JavaWebApi.service.systemService.IApiRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

@RestController
@RequestMapping("/api/apiRole")
@Api(tags="apiRole")
@Authorize(validApi = true)
public class ApiRoleController {
    @Autowired
    private IApiRoleService apiRoleService;
    @ApiOperation("获取全部控制器节点")
    @GetMapping("getList")
    public List<ControllerDescription> getList(){
        return apiRoleService.getList();
    }
    @ApiOperation("接口授权")
    @PostMapping("save")
    public Boolean save(@RequestBody @Validated ApiRoleVo apiRole){
        return apiRoleService.save(apiRole);
    }
    @ApiOperation("获取角色的接口id")
    @GetMapping("getRoleApi")
    public List<String> getRoleApi(Integer roleId){
        return apiRoleService.getRoleApi(Collections.singletonList(roleId),null);
    }
}
